/*
 * @Description: 
 * @Author: paddies
 * @Date: 2023-12-06 17:59:53
 * @LastEditors: paddies
 * @LastEditTime: 2025-08-16 00:26:31
 * @FilePath: /luntai-user-app/Users/paddies/Desktop/code/A-team/luntai/shared_components/lib/build-radio-group/buildRadioGroup.dart
 */
import 'package:flutter/material.dart';
import 'package:shared_components/build-common/buildCommon.dart';
import 'package:shared_components/build-image/buildImage.dart';

Widget buildRadioGrou(
    {List list = const [],
    String activeValue = '',
    Color activeColor = const Color(0xff0101ec),
    Function? onChange,
    int widthFactor = 2}) {
  return Container(
      width: double.infinity,
      // height: 200,
      color: Colors.white,
      child: Wrap(
          spacing: 0, //主轴上子控件的间距
          runSpacing: 0,
          children: [
            ...list.map((e) {
              return FractionallySizedBox(
                  widthFactor: 1 / widthFactor,
                  child: Row(
                    crossAxisAlignment: CrossAxisAlignment.center,
                    mainAxisAlignment: MainAxisAlignment.start,
                    children: [
                      Radio(
                        // 按钮的值
                        value: e['value'],
                        activeColor: activeColor,

                        // 改变事件
                        onChanged: (value) {
                          if (onChange != null) {
                            onChange(value);
                          }
                        },
                        // 按钮组的值
                        groupValue: activeValue,
                      ),
                      Expanded(
                          child: GestureDetector(
                              onTap: () {
                                if (onChange != null) {
                                  onChange(e["value"]);
                                }
                              },
                              child: Text(
                                showText(e["label"]),
                                overflow: TextOverflow.ellipsis,
                              ))),
                    ],
                  ));
            }).toList(),
          ]));
}

// RadioListTile(
//   value: 1,
//   groupValue: 0,
//   onChanged: (value) {},
//   title: Text(
//     "轮胎调位+换备胎",
//     style: TextStyle(fontSize: 14),
//   ),
//   // subtitle: Text("这是二级标题"),
//   // secondary: Icon(Icons.help),
//   selected: false,
// ),
Color activeBgColor = Color(0xfffdf6f7);
Color disabledColor = Color(0xffa1a1a1);
Widget buildNewRadioGrou(
    {List list = const [],
    String activeValue = '',
    Color activeColor = const Color(0xffF9110D),
    Function? onChange,
    int widthFactor = 2}) {
  return Container(
      width: double.infinity,
      // height: 200,
      color: Colors.white,
      child: Wrap(
          spacing: 0, //主轴上子控件的间距
          runSpacing: 0,
          children: [
            ...list.map((e) {
              return FractionallySizedBox(
                  widthFactor: 1 / widthFactor,
                  child: GestureDetector(
                    onTap: () {
                      if (onChange != null) {
                        onChange(e["value"]);
                      }
                    },
                    child: Container(
                      padding: EdgeInsets.only(left: 4, right: 4),
                      child: Row(
                        crossAxisAlignment: CrossAxisAlignment.center,
                        mainAxisAlignment: MainAxisAlignment.center,
                        children: [
                          Expanded(
                              child: Container(
                            margin: EdgeInsets.only(top: 5, bottom: 5),
                            decoration: BoxDecoration(
                                borderRadius: const BorderRadius.all(
                                    Radius.circular(8.0)),
                                color: activeValue == e['value']
                                    ? activeBgColor
                                    : Color(0xfff7f7f7),
                                border: Border(
                                  left: BorderSide(
                                      width: 1.5,
                                      color: activeValue == e['value']
                                          ? activeColor
                                          : Colors.transparent),
                                  right: BorderSide(
                                      width: 1.5,
                                      color: activeValue == e['value']
                                          ? activeColor
                                          : Colors.transparent),
                                  top: BorderSide(
                                      width: 1.5,
                                      color: activeValue == e['value']
                                          ? activeColor
                                          : Colors.transparent),
                                  bottom: BorderSide(
                                      width: 1.5,
                                      color: activeValue == e['value']
                                          ? activeColor
                                          : Colors.transparent),
                                )),
                            padding: EdgeInsets.only(
                                left: 10, right: 10, top: 10, bottom: 10),
                            child: Row(
                              children: [
                                Container(
                                    width: 20,
                                    height: 20,
                                    child: buildImage(
                                        url: "assets/images/common/" +
                                            e["icon"] +
                                            ".png",
                                        fit: BoxFit.fill)),
                                SizedBox(
                                  width: 3,
                                ),
                                Expanded(
                                    child: Text(
                                  showText(e["label"]),
                                  overflow: TextOverflow.ellipsis,
                                  style: TextStyle(
                                    fontWeight: FontWeight.bold,
                                    fontSize: 14,
                                    color: activeValue.contains(e['value'])
                                        ? activeColor
                                        : disabledColor,
                                  ),
                                ))
                              ],
                            ),
                          ))
                          // Radio(
                          //   // 按钮的值
                          //   value: e['value'],
                          //   activeColor: activeColor,

                          //   // 改变事件
                          //   onChanged: (value) {
                          //     if (onChange != null) {
                          //       onChange(value);
                          //     }
                          //   },
                          //   // 按钮组的值
                          //   groupValue: activeValue,
                          // ),
                          // Expanded(
                          //     child: GestureDetector(
                          //         onTap: () {
                          //           if (onChange != null) {
                          //             onChange(e["value"]);
                          //           }
                          //         },
                          //         child: Text(
                          //           showText(e["label"]),
                          //           overflow: TextOverflow.ellipsis,
                          //         ))),
                        ],
                      ),
                    ),
                  ));
            }).toList(),
          ]));
}
